﻿<#assign classNameLower = className?uncap_first>
<%@ page contentType="text/html; charset=gb2312"%>
<%@ page import="com.shareinfo.smbase"%>
<%@ page import="com.shareinfo.TGlobal"%>
<%@ page import="com.shareinfo.dbc.TResultSet"%>
<%@ page import="${packageName}.${className}ManageOper"%>
<%
    request.setCharacterEncoding("gb2312");    
	response.setHeader("Pragma", "No-cache");
	response.setHeader("Cache-Control", "no-cache");
	response.setDateHeader("Expires", 0);	
%>
<html>
	<head>
		<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
		<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
		<META HTTP-EQUIV="Expires" CONTENT="0">
		<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
		<link rel="stylesheet" type="text/css" href="../../include/style.css">
		<jsp:useBean id="beanOper" scope="session" class="com.shareinfo.TOperator" />
		<jsp:useBean id="${classNameLower}Bean" scope="request" class="${packageName}.${className}Bean">
			<jsp:setProperty name="${classNameLower}Bean" property="*"/>
		</jsp:useBean>
		<title>添加/修改${comments}</title>			
		<script language="JavaScript" type="text/javascript" src="../../include/func.js"></script>
		<script language="JavaScript" type="text/JavaScript">
			//修改、添加的时候调用的函数
			function btnSubmitOnClick(operType)
			{
				<#list table.columns as column>
					${column.classColumnName} = document.frmOk.${column.classColumnName};
					if(${column.classColumnName}.value == '' || ${column.classColumnName}.value == null)
					{
						alert("${column.sqlRemarks}不能为空，请输入!");
						${column.classColumnName}.focus();
						return false;
					}	
				</#list>
				
			  	document.frmOk.pageSubmit.value = "1";
			  	document.frmOk.pageAction.value = operType;
			  	document.frmOk.submit();
			}
			function btnBackOnClick()
			{
				window.location.href="./${classNameLower}.jsp";
			}
		</script>
	</head>
	<body background="../../images/right_bg.gif">
	<%
		//如果用户没有登录，则跳转到登录页面
		if (!beanOper.isLogin) {
			out.println("<script language=\"JavaScript\">");
			out.println("	window.parent.location = \"../../index.jsp?logout=1\" ");
			out.println("</script>");
		}
		
		boolean hasRightA = beanOper.HasRight("B7A");
		boolean hasRightB = beanOper.HasRight("B7B");
		
		if (!hasRightA) {
			out.println("<script language=\"JavaScript\">");
			out.println("	alert('您没有浏览${comments}的权限，不能浏览！');");
			out.println("	window.history.go(-1); ");
			out.println("</script>");
		}	
		String pageAction = smbase.BlankNull(request.getParameter("pageAction"), "0"); 
		String pageSubmit = smbase.BlankNull(request.getParameter("pageSubmit"), "0");
		${className}ManageOper ${classNameLower}ManageOper = new ${className}ManageOper(beanOper);
		//添加
		if("1".equals(pageAction) && "1".equals(pageSubmit)){
			int ret = -1;
			ret = ${classNameLower}ManageOper.insert${className}(${classNameLower}Bean);
			out.println("<script language='javascript'>");
			if(ret > 0){				
				out.println("alert('添加操作成功！');btnBackOnClick();");				
			}else{
				out.println("alert('添加操作失败')");
			}
			out.println("</script>");
		}
		//修改
		if("2".equals(pageAction) && "1".equals(pageSubmit)){
			int ret = -1;
			ret = ${classNameLower}ManageOper.update${className}(${classNameLower}Bean);
			out.println("<script language='javascript'>");
			if(ret > 0){				
				out.println("alert('修改操作成功！')");
			}else{
				out.println("alert('修改操作失败！')");				
			}
			out.println("</script>");
		}	
		//查看
		if(("0".equals(pageAction) || "2".equals(pageAction)) && "0".equals(pageSubmit)){
			${classNameLower}Bean = ${classNameLower}ManageOper.query${className}ById(${classNameLower}Bean.getId());
		}
	%>
		<table width="100%" border="0" align="center" cellpadding="2" cellspacing="0">
			<tr>
				<td width="62%" height="26" valign="bottom" background="../../images/main_bg_top1.jpg">
					<div align="left">
						<table width="300" height="20" border="0" cellpadding="0"
							cellspacing="0">
							<tr>
								<td width="3%">&nbsp;</td>
								<td width="97%" valign="bottom" class="newstitle">
									<strong>
										<font color="#FFFFFF">
											<%
											if("0".equals(pageAction)){
												out.println("查看${comments}");
											}else if("1".equals(pageAction)){
												out.println("添加${comments}");
											}else if("2".equals(pageAction)){
												out.println("修改${comments}");
											}										
											%>
										</font>
									</strong>
								</td>
							</tr>
						</table>
					</div>
				</td>
				<td width="38%" valign="bottom" background="../../images/main_bg_top11.jpg">
					<img src="../../images/refresh.gif" width="13" height="16"
						alt="刷新当前页面" onClick="javascript:location.reload()">
				</td>
			</tr>
		</table>
		<form action="" method="post" name="frmOk">
		<input type="hidden" name="pageSubmit" id="pageSubmit" value="0">
		<input type="hidden" name="pageAction" id="pageAction" value="0">
		<table width="100%" height="90%" border="0" align="center" cellspacing="0">			
			<tr>
				<td height="82">
					<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#999999">
						<tr>
							<td bgcolor="#EFF8FF">
								<table width="100%" border="0" cellspacing="0">
									<#list table.columns as column>
									<tr>
										<td style="text-align:right;width:20%">
											<span><font color="red">*</font></span>${column.sqlRemarks}：											
										</td>
										<td style="width:80%">
											<input type="text" style="width:55%;" name="${column.classColumnName}" value="<%=${classNameLower}Bean.get${column.classColumnName?cap_first}()%>">
										</td>
									</tr>		
									</#list>
									<tr>
										<td style="text-align:right">&nbsp;</td>
										<td>&nbsp;</td>
									</tr>
									<tr>
										<td style="text-align:right">&nbsp;</td>
										<td>&nbsp;</td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td valign="top">
					<table width="98%" border="0" align="center" cellspacing="0">
						<tr>
							<td width="50%" style="text-align:right">
								<input  type="button"  id="btnSubmit" name="btnSubmit"
									onClick="return btnSubmitOnClick('<%=pageAction%>');" value=" 提交 " <%=("0".equals(pageAction))?"disabled":"" %>>
							</td>
							<td width="50%" style="text-align:left">
								<input  type="button"  id="btnBack" name="btnBack" value=" 返回 "
									onClick="return btnBackOnClick()">
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td valign="bottom">
					<table width="100%" border="0" align="right" cellpadding="0"
						cellspacing="0">
						<tr>
							<td background="../../images/main_bg_b.jpg">&nbsp;</td>
						</tr>
					</table>
				</td>
			</tr>			
		</table>
		</form>
	</body>
</html>